package com.sofwin.service.impl;

import com.sofwin.dto.ResourceDto;
import com.sofwin.mapper.SysResourceMapper;
import com.sofwin.pojo.SysResource;
import com.sofwin.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * postman
 * 请求测试
 */
import java.util.List;
@Service
public class ResourceServiceImpl implements ResourceService {

    @Autowired
    private SysResourceMapper mapper;
    @Override
    public List<ResourceDto> selectAllResources() {
        return mapper.selectAllResourceForTree();
    }

    @Override
    public List<SysResource> selectAllResources2() {
        return mapper.selectAllResourceForTree2();
    }

    @Override
    public boolean save(SysResource resource) {
        if(resource.getId()!=null){
            return mapper.updateByPrimaryKeySelective(resource)==1?true:false;
        }
        return mapper.insertSelective(resource)==1?true:false;
    }

    @Override
    public SysResource selectById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public boolean deleteById(Integer id) {
        return mapper.deleteByPrimaryKey(id)==1?true:false;
    }

    @Override
    public List<ResourceDto> selectResourceByRoled(Integer roleId) {
        return mapper.selectAllResourceForTreeByRoleId(roleId);
    }

    @Override
    public List<ResourceDto> selectRoleResource(Integer roleId) {

        return mapper.roleResource(roleId);
    }

    @Override
    public List<SysResource> selectResourceByRoleId(Integer roleId) {
        return mapper.selectResourceByRoleId(roleId);
    }
}
